package com.csd.controller;

import com.csd.dto.ActionResult;

import com.csd.mapper.SysOrderMapper;
import com.csd.po.PageOrder;
import com.csd.po.SysUser;

import com.csd.service.SysOrderService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 订单控制层（接口）
 *
 * @author qinjianbao
 * @date 2020/12/23 10:30
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    /**
     * 添加订单
     */
    @Autowired(required = false)
    private SysOrderService sysOrderService;

    @RequestMapping(value = "/addOrder",method = RequestMethod.GET)
    @ResponseBody
    public ActionResult addOrder(Integer getid,Integer backid,Integer cid,Double oprice,HttpSession session){

        System.out.println("订单模块");
        SysUser user = (SysUser) session.getAttribute("user");
        if(user==null){
            return new ActionResult(200,"请您登录",null);
        }else {
            sysOrderService.addOrder(user.getId(),cid,getid,backid,oprice);
            return new ActionResult(200,"预定成功",null);
        }

    }
    /**
     * 查询全部订单
     *
     * @return
     */
    @RequestMapping(value = "/selectAll",method = RequestMethod.GET)
    @ResponseBody
    public ActionResult selectAll(HttpSession session,Integer page){
        System.out.println("分页");
        /*Integer page=1;*/

        System.out.println(page);
        SysUser user = (SysUser) session.getAttribute("user");
        List<PageOrder> list =sysOrderService.selectAll(user.getId(),page);
        for (PageOrder pageOrder:list){
            System.out.println(pageOrder);
        }
        return new ActionResult(200,null,list);
    }


    /**
     * 删除订单
     */
    @RequestMapping("/delById")
    @ResponseBody
    public ActionResult delById(Integer id){
        System.out.println("删除");
        System.out.println(id);
        sysOrderService.delOrderById(id);
        return new ActionResult(200,null,null);
    }
}
